
/**
 * 
 * @param array
 * @returns
 */
function getMin(array)
{
	return Math.min.apply(Math, array);
}

/**
 * 
 * @param array
 * @returns
 */
function getMax(array)
{
	return Math.max.apply(Math, array);
}

/**
 * @param array
 * @param x
 * @param y
 * @param offset
 * @returns
 */
function getObjectId(array, x, y, offset)
{
	//console.log("THisds is good tooo ");
	var ret = searchCoordinates(array, x, y, offset);
	
	var tmp = null;
	
	if (ret != null)
	{
		if (shape_manager.data[ret].id != 0)
		{
			// At this point we know the shape
			// So we need to check that nothing is inside
			
			tmp = getObjectId(array, x, y, ret - 1);
			
			if (tmp != null) {return tmp;};
			
		}
	}
	
	return ret;
}

/**
 * @param array
 * @param x
 * @param y
 * @param offset
 * @returns
 */
function searchCoordinates(array, x, y, offset)
{
	if (offset >= 0 && offset < shape_manager.data.length)
	{
		for (var i = offset ; i >= 0 ; i--)
		{
			if (shape_manager.data[i].isMouseHover(x, y))
			{
				return i;
			}
			
		}
	}
	
	return null;
}

function getDistance(x1, y1, x2, y2){

	var dx = x2 - x1;
    var dy = y2 - y1;  
	
	 return Math.sqrt( Math.pow( dx, 2 ) + Math.pow( dy, 2 ) );
}

function getAngle(x1, y1, x2, y2){

				var dx = x2 - x1;
                var dy = y2 - y1;      
				
                return Math.atan2( dx, dy );
}


Array.prototype.getItemCount = function(item) {
    var counts = {};
    for(var i = 0; i< this.length; i++) {
        var num = this[i];
        counts[num] = counts[num] ? counts[num]+1 : 1;
    }
    return counts[item] || 0;
}